package cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.service;

import cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.entity.EmployeeAssInstruction;
import cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.mapper.EmployeeAssInstructionMapper;
import cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.util.SnowflakeIdGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 张烁瑜
 * @Date 2025/5/27 21:26
 */
@Service
public class EmployeeAssInstructionService {

    @Autowired
    private EmployeeAssInstructionMapper employeeAssInstructionMapper;

    @Autowired
    private SnowflakeIdGenerator idGenerator; // 注入雪花ID生成器

    public String save(EmployeeAssInstruction employeeAssInstruction) {
        // 生成雪花ID并设置到实体
        long snowflakeId = idGenerator.generateId();
        employeeAssInstruction.setId(snowflakeId);

        if (employeeAssInstructionMapper.save(employeeAssInstruction)) {
            return "保存成功";
        }
        return "保存失败";
    }
    public String delete(Long id) {
        if (employeeAssInstructionMapper.delete(id)) {
            return "删除成功";
        }
        return "删除失败";
    }
    public String update(EmployeeAssInstruction employeeAssInstruction) {
        if (employeeAssInstructionMapper.update(employeeAssInstruction)) {
            return "修改成功";
        }
        return "修改失败";
    }

    public PageInfo<EmployeeAssInstruction> get(int pageNum, int pageSize, EmployeeAssInstruction employeeAssInstruction){
        PageHelper.startPage(pageNum,pageSize);
        List<EmployeeAssInstruction> employeeAssInstructionList  = employeeAssInstructionMapper.get(employeeAssInstruction);
        return PageInfo.of(employeeAssInstructionList);
    }
}
